package com.xiaozhen.jt809.utils;

/**
 * HISTORY
 *
 * @author zhenweisheng
 * @date 2021/9/14 10:52
 * @description:
 */
public class EncryptUtil {

    public static byte[] encrypt(long M1,long IA1,long IC1, long key, byte[] data) {
        int idx = 0;

        int size = data.length;

        if (key == 0) {
            key = 1;
        }
        long mkey = M1;
        if (0 == mkey) {
            mkey = 1;
        }
        while (idx < size) {
            key = IA1 * (key % mkey) + IC1;
            Long x = ((key >> 20) & 0xFF);
            data[idx++] ^= x;
        }
        return data;
    }
}
